/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hvtt.web.connection;

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 *
 * @author Administrator
 */
public class ConnectionPoolListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        
        DatasourceConnection.initDatasource();
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        DatasourceConnection.closeDatasource();
        Enumeration<Driver> drivers = DriverManager.getDrivers();
        
        while (drivers.hasMoreElements()) {
            Driver driver = drivers.nextElement();
            try {
                DriverManager.deregisterDriver(driver);
                sce.getServletContext().log(
                        "(JDBC driver (" + driver.toString()
                        + ") successfully deregistered");
            } catch (SQLException ex) {
                sce.getServletContext().log(ex.getMessage());
            }

        }
    }
    
}
